package com.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @Classname CallableDemo
 * @Description TODO
 * @Date 2020/6/6 23:03
 * @Created by xiangty
 */
public class CallableDemo implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("执行了CallableDemo#call");
        return "call返回值";
    }
}


class CallableDemoTest {
    public static void main(String[] args) throws Exception {
        CallableDemo callableDemo = new CallableDemo();
        FutureTask<String> futureTask = new FutureTask<String>(callableDemo);
        Thread thread = new Thread(futureTask);
        thread.start();
        System.out.println("一定要用FutureTask的get()方法，不然线程直接过执行过了,取不到值。\n 线程返回值：" + futureTask.get());
    }
}